package com.atlzk.renting.house.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.atlzk.common.entity.house.HouseEntity;
import com.atlzk.common.utils.PageUtils;
import com.atlzk.common.utils.Query;
import com.atlzk.renting.house.dao.HouseDao;
import com.atlzk.renting.house.service.HouseService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("houseService")
public class HouseServiceImpl extends ServiceImpl<HouseDao, HouseEntity> implements HouseService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<HouseEntity> page = this.page(
                new Query<HouseEntity>().getPage(params),
                new QueryWrapper<HouseEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 分页列表
     */
    @Override
    public IPage houseList(HouseEntity houseEntity, Integer page, Integer size) {
        QueryWrapper <HouseEntity> queryWrapper = new QueryWrapper <HouseEntity>();
        queryWrapper
                .eq(ObjectUtil.isNotNull(houseEntity.getProvinceId()),"province_id",houseEntity.getProvinceId())
                .eq(ObjectUtil.isNotNull(houseEntity.getCityId()),"city_id",houseEntity.getCityId())
                .eq(ObjectUtil.isNotNull(houseEntity.getCountyId()),"county_id",houseEntity.getCountyId());
        Page houseEntityPage = new Page <HouseEntity>(page,size);
        IPage iPage = baseMapper.selectPage(houseEntityPage, queryWrapper);
        return iPage;
    }



}